package Pages;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import selenium.WebDriverWrapper;
import utils.Log4Test;

import java.net.URL;
import java.util.concurrent.TimeUnit;

/**
 * Created by Time to be on 06.07.2014.
 */
public class BasePage {
    protected String url = "http://rozetka.com.ua";
    protected WebDriverWrapper driver;
    private static final By search = By.xpath("//*[@id='body-header']/div[2]/div/div/div/div[2]/form/div[2]/div[1]/input");

    public BasePage(WebDriverWrapper driver){
        this.driver = driver;
    }


    public void open () {
        driver.get(url);
    }

    public void open (String url) {
        driver.get(url);
    }

    public boolean isOpened(){
        return driver.getCurrentUrl().equals(url);
    }

    public String searchProduct(String product) {
        WebDriverWait wait = new WebDriverWait(driver, 10);

        Log4Test.onCurrentPage("BasePage");

        driver.findElement(search).clear();
        driver.findElement(search).sendKeys(product);
        driver.findElement(search).sendKeys(Keys.ENTER);
        driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
        return url = driver.getCurrentUrl();
    }


//end.
}
